﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using BLL;
using Model;
using System.Data.SqlClient;
namespace UI
{
    public partial class Frm修改会员 : Form
    {
        public Frm修改会员()
        {
            InitializeComponent();
        }
        //确认框修改
        private void button1_Click(object sender, EventArgs e)
        {

            if (txtName.Text != "" && txtTel.Text != "")
            {

                Model_Vips.VipName = txtName.Text;
                Model_Vips.VipTel = txtTel.Text;

                if (radnan.Checked)
                {
                    Model_Vips.VipSex = radnan.Text;
                }
                if (radnv.Checked)
                {
                    Model_Vips.VipSex = radnv.Text;
                }
                Model_Vips.GradeID = cbbDengji.SelectedValue.ToString();
                Model_Vips.VipEndDate = DateTime.Parse(dateTimePicker1.Text);
                int a = BLLCHAallhy.XGvip();
                if (a > 0)
                {
                    MessageBox.Show("修改成功");
                    this.Close();//触发了窗体的关闭事件
                }
            }
            else
            {
                MessageBox.Show("请输入完整信息！！！");
            }


        }

        private void Frm修改会员_Load(object sender, EventArgs e)
        {
            DataSet ds = BLLCHAallhy.BLLchahuiyuandengji();
            this.cbbDengji.DataSource = ds.Tables[0];
            this.cbbDengji.ValueMember = "VGID";//隐藏列
            this.cbbDengji.DisplayMember = "VGName";

            int count = 0;
            foreach (DataRow item in ds.Tables[0].Rows)
            {
                if (item["VGName"].ToString() == Model_Vips.GradeID)
                {
                    this.cbbDengji.SelectedIndex = count;
                    break;
                }
                count++;
            }

            SqlDataReader dr = BLLCHAallhy.BLLchahyBYid();
            while (dr.Read())
            {
                txtName.Text = dr[1].ToString();
                txtTel.Text = dr[5].ToString();
                 radnan.Checked = true;
                 if (dr[2].ToString() == "女")
                 {
                     radnv.Checked = true;
                 }
                 this.dateTimePicker1.Value = DateTime.Parse(dr[7].ToString());
            }
            dr.Close();
        }

        private void Frm修改会员_FormClosing(object sender, FormClosingEventArgs e)
        {
            e.Cancel = false;
            FrmHuiyuanguanli f = new FrmHuiyuanguanli();
            f.Show();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
